package com.changgou.item.listener;

import com.changgou.item.service.PageService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @Author: wzw
 * MQ监听消息并生成静态页。
 * @Date: 2020/12/19 12:43
 * @version: 1.8
 */
@Component
public class PageListener {

    //注入service
    @Autowired
    private PageService pageService;

    @RabbitListener(queues = {"item-queue"})
    public void index(String id) {
        System.out.println("item_id = " + id);
        //判空
        if (!StringUtils.isEmpty(id)) {
            //实现功能:调用创建静态方法
            pageService.createHtml(Long.parseLong(id));
        }
    }

}
